package androidvn.xenforo.fourums.adapter;

import java.util.ArrayList;

import androidvn.xenforo.fourums.R;
import androidvn.xenforo.fourums.model.Node;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomNodeListAdapter extends BaseAdapter {
	Context context;
	ArrayList<Node> nodeList;

	public CustomNodeListAdapter(Context context, ArrayList<Node> nodeList) {
		super();
		this.context = context;
		this.nodeList = nodeList;
	}

	@Override
	public int getCount() {
		return nodeList.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup viewGroup) {
		ViewHolder holder = null;

		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.forum_node_list_item,
					viewGroup, false);

			holder = new ViewHolder();

			holder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle);
			holder.tvDescription = (TextView) convertView
					.findViewById(R.id.tvDescription);
			holder.ivIcon = (ImageView) convertView.findViewById(R.id.ivIcon);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		//
		holder.tvTitle.setText(nodeList.get(position).getTitle());
		holder.tvDescription.setText(nodeList.get(position).getDescription());

		return convertView;
	}

	static class ViewHolder {
		TextView tvTitle, tvDescription;
		ImageView ivIcon;

	}
}
